package com.gs.weather.dao;

import com.gs.weather.dao.mapper.DisasterProcessMapper;
import com.gs.weather.entity.DisasterProcess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/21 0021
 */
@Repository
public class DisasterProcessDao {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    DisasterProcessMapper mapper;

    //添加灾情过程信息
    public Long addDisasterProcess(DisasterProcess disasterProcess) {
        try {
            mapper.addDisasterProcess(disasterProcess);
            return disasterProcess.getId();
        } catch (Exception e) {
            logger.info("addDisasterProcess失败->{}", e.getMessage());
            return null;
        }
    }

    //更新灾情过程信息
    public void updateDisasterProcess(DisasterProcess disasterProcess) {
        try {
            mapper.updateDisasterProcess(disasterProcess);
        } catch (Exception e) {
            logger.info("updateDisasterProcess失败->{}", e.getMessage());
        }
    }


    //查询某街镇(某年、某月、某年某月)所有灾情过程信息
    public List<DisasterProcess> queryAllProcessesWithCondition(String name, String likeTime) {
        try {
            List<DisasterProcess> disasterProcesses = mapper.queryAllDisasterProcessWithXsAreaNameOrTime(name, likeTime);
            return disasterProcesses;
        } catch (Exception e) {
            logger.info("queryAllProcessesWithCondition失败->{}", e.getMessage());
            return null;
        }
    }

    //根据id查询灾情过程信息
    public DisasterProcess queryDisasterProcessById(long id) {
        try {
            DisasterProcess disasterProcess = mapper.queryDisasterProcessById(id);
            return disasterProcess;
        } catch (Exception e) {
            logger.info("queryDisasterProcessById失败->{}", e.getMessage());
            return null;
        }
    }

    //删除灾情过程信息
    public void deleteDisasterProcess(long id) {
        try {
            mapper.deleteDisasterProcess(id);
        } catch (Exception e) {
            logger.info("deleteDisasterProcess失败->{}", e.getMessage());
        }
    }
}
